#ifndef _RES_MANAGER_H_
#define _RES_MANAGER_H_

#include "vfs_tests.h"
#include "resHashMap_test.h"
#include "gtest/gtest.h"
#include "testLogWriter.h"
#include "core/core_utils.h"
#include "resource_system/resourceManager.h"


class resManagerFixtureTest : public ::testing::Test
{
public:

	const std::string TEST_APP;
	CTestLogWriter* m_tlw;
	lpe::resman::ResManager* m_resman;

	void SetUp()
	{
		// Setting up the logger
		glog::CGlobalLog& m_log = glog::CGlobalLog::getSingleton();
		m_log.addAppender(TEST_APP);
		m_log.addListener(m_tlw, TEST_APP);
		m_log.setMiniumLevel(glog::LOGLEVEL_DEBUG);

		// Setting up resource manager
		lpe::resman::ResManager::initSingleton();
		m_resman = &lpe::resman::ResManager::getSingleton();
	}
	void TearDown()
	{
		// Tearing down the log.
		glog::CGlobalLog& m_log = glog::CGlobalLog::getSingleton();
		m_log.processMessages();
		boost::filesystem::remove(boost::filesystem::path("datasources.xml"));
	}
	bool setUpDatasourceConfigFile()
	{
		boost::filesystem::path p("datasources.xml.bak");
		boost::filesystem::path d("datasources.xml");
		if(boost::filesystem::exists(p))
		{
			boost::filesystem::copy_file(p,d);
			return true;
		}
		return false;
	}

	resManagerFixtureTest()
		:TEST_APP("[TEST]")
	{
		glog::CGlobalLog::initSingleton();
		m_tlw = new CTestLogWriter(false);
	}

	virtual ~resManagerFixtureTest(){

	}
};

TEST_F(resManagerFixtureTest,create_a_simple_resource_manager_wo_config_file)
{
	EXPECT_THROW(m_resman->init(),lpe::core::fileNotFoundException);
}

TEST_F(resManagerFixtureTest, create_resource_manager_w_default_config_file)
{
	EXPECT_TRUE(setUpDatasourceConfigFile());
	EXPECT_NO_THROW(m_resman->init());
}
TEST_F(resManagerFixtureTest, deploy_a_raw_file)
{
	EXPECT_TRUE(setUpDatasourceConfigFile());
	EXPECT_NO_THROW(m_resman->init());
	boost::filesystem::path p(m_resman->getDataSourceByName("main")->getWriteDirectory());
	p /= boost::filesystem::path("hola.txt");
	EXPECT_EQ(p.string(), m_resman->getRawFileByName("main","hola.txt"));
	EXPECT_TRUE(boost::filesystem::exists(p));
}
TEST_F(resManagerFixtureTest, loadResource_non_existent_file_returns_null)
{
	EXPECT_EQ(0, m_resman->loadResource("main","nonExistentFile.xml"));
}

/*
TEST_F(resManagerFixtureTest, load_simple_resource_returns_resource_object_reference)
{
	//lpe::resman::Resource* res = m_resman->loadResource("main","testStrings_1.xml");

	//EXPECT_EQ(res->getID(),122313);
}
*/
#endif //_RES_MANAGER_H_
